package com.gizwits.kafkaActor

import java.util.Properties

import com.gizwits.util.CaseClasssDomain.User
import com.gizwits.util.Constants
import kafka.producer.{KeyedMessage, Producer, ProducerConfig}
import scala.collection.JavaConversions._

class  Product{

}
object Product {
  //test genter info data
  def genMsg(num:Int)={

    val  ulist= collection.mutable.ListBuffer[User]()

    for(i <-1 to  num){
      ulist.+=:(User("feel"+1,10+i))
    }
    ulist

  }
  def main(args: Array[String]) {

    val props = new Properties()
    props ++= Map(
      "serializer.class" -> Constants.SERIALIZEENCODERRCLASS,
      "metadata.broker.list" -> Constants.BROKERS,
      "key.serializer.class" ->"kafka.serializer.StringEncoder",
      "producer.type"-> "async",
      "compression.codec" -> "snappy"
    )
    val config = new ProducerConfig(props)
    val producer = new Producer[String, User](config)
    for(u<-genMsg(10))
    {
      println(u)
      producer.send(new KeyedMessage[String, User](Constants.KafkaTopic, u))
    }

    producer.close()
  }
}
